package org.csy.work.servlet;


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.csy.work.dao.ProductTypeDao;
import org.csy.work.dao.impl.ProductTypeDaoImpl;
import org.csy.work.entity.ProductType;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author ZJL
 * @date 2024-11-25
 */
@WebServlet("/productType.do")
public class ProductTypeListServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        ProductTypeDao productTypeDao = new ProductTypeDaoImpl();
        List<ProductType> list = productTypeDao.getProductTypeAll();

        Gson gson = new Gson();
        String json = gson.toJson(list);
        PrintWriter out = resp.getWriter();
        out.write(json);
        out.flush();
        out.close();
    }
}
